//
//  Application.swift
//  App
//
//  Created by Flutter on 2021/7/6.
//
import UIKit
import UICore
import App_Login
import App_Vision
import App_Hearing
import App_Archives
import App_Main
import App_Common
import Leaf
import Service
import Standard
import Center

private extension Application {
    static var window: UIWindow?
    
    static let bootstrapperList: [Bootable.Type] = [
        Service.Bootstrapper.register(environment: ServiceEnvironment()).self,
        Center.Bootstrapper.register(environment: CenterEnvironment()).self,
    ]
    
}

public extension Application {
    static func scene(_ scene: UIWindowScene, willConnectTo session: UISceneSession, options connectionOptions: UIScene.ConnectionOptions) -> UIWindow? {
        makeWindow(scene)
        bootstrap()
        setup()
//        print("iphone scale \(UIScreen.main.scale)")
        
        return window
    }
}

private extension Application {
    
    static func makeWindow(_ scene: UIWindowScene) {
        window =
            UIWindow(windowScene: scene)
            .leaf
            .backgroundColor(.systemBackground)
            .makeKeyAndVisible()
            .instance
    }
    
    static func bootstrap() {
       
        
        bootstrapperList.forEach { $0.bootstrap() }
        
    }
    
    static func setup() {
      
        
        
        
        window?.rootViewController = mainViewControllerType.init(viewControllers: [
            visionNavigationControllerType.init(),
            hearingNavigationControllerType.init(),
            archivesNavigationControllerType.init(),
        ])

    
        
    }
}
